<?php

if (!empty($this->searchItem)) {
       $HTMLstr .= '<div class="body">
            <div class="head">
            Посты '. $this->itemCat .' <b>'. $this->searchItem .'</b>:
            </div>';
    } else {

        $HTMLstr .= '<div class="body">
           <div class="subMenu">
            <a href="index.php?controller=news&action=edit">Создать пост</a>
           <a href="?controller=news&action=filter">Фильтр постов</a>
           </div>';
    }

if (null != $this->allModels) { //сюда из fetchAll
    
    
    foreach($this->allModels as $oneModel) {
        $HTMLstr .= '<div class="fetchallOne"';
        if(0 != $oneModel->getImg()) {
            $HTMLstr .= 'id="withImg"';
        }
        $HTMLstr .= '>';

        if(0 != $oneModel->getImg()) {
            $HTMLstr .= '<div class="fetchallOneInsideImg">
                <img height="200px" src="stuff/images/saved/'. model_ConfigMapper::findAvatar($oneModel->getImg()) .'.jpg">
                </div>';
        }

        $HTMLstr .= '<div class="fetchallOneInside">';
        
        $HTMLstr .=  '
            <div class="fetchallOneInsideAvatar">
            <a href="?controller=user&id='. $oneModel->getAuthor() .'">
            <img height="100%" src="stuff/images/saved/'. model_ConfigMapper::findAvatar2($oneModel->getAuthor()) .'.jpg">
            </a>
            </div>
            <div class="fetchallOneInsideTitle">

            Добавил:
            </div>
            <div class="fetchallOneInsideTitle">
            <a href="?controller=user&id='. $oneModel->getAuthor() .'">'
                . model_ConfigMapper::findAuthor($oneModel->getAuthor()) .'</a>
             </div>
             <div class="fetchallOneInsideText">'. $oneModel->getDate() .'
             </div>
             </div>';
        
$HTMLstr .= '<div class="fetchallOneInsideContent">
    <div class="fetchallOneInsideTitle">
    Тема: <b>' . $oneModel->getTitle() .'</b>
    </div>
    <div class="fetchallOneInsideText" id="clear">
    Тэги: ';
$allTags = model_ConfigMapper::getTags($oneModel->getId());
if(!empty($allTags)) {
    foreach($allTags as $oneTag) {
        $HTMLstr .= '<a href="index.php?controller=news&action=byTag&id='. $oneTag->getId() .'">'. $oneTag->getText() .'</a> ';
    }
    $HTMLstr .= '</div>';
} else {
    $HTMLstr .= 'Без тегов
        </div>';
}
    $HTMLstr .= '</div>
    <div class="fetchallOneInsideAct">
    <a href="index.php?controller=news&action=index&id='.$oneModel->getId().'">смотреть</a>
        </div>';
if (null != $user->getId()) {
            if ( $user->getRole()=='admin' OR  $user->getId()==$oneModel->getAuthor()) {
                $HTMLstr .= '<div class="fetchallOneInsideAct">
                    <a href="index.php?controller=news&action=edit&id='.$oneModel->getId().'">редактировать</a>
                    </div>
                    <div class="fetchallOneInsideAct">
                    <a href="index.php?controller=news&action=delete&id='.$oneModel->getId().'">удалить</a>
                    </div>';
            }
        }
        
$HTMLstr .= '</div>';
    }

    if (null != $user->getId()) {
        if (!empty($this->searchItem)) {
            $HTMLstr .= '<div class="space"></div>
                <div class="fetchallOneInsideAct">
                <a href="index.php">Ко всем новостям</a>
                </div>
                <div class="fetchallOneInsideAct">
                  <a href="index.php?controller=tag">К списку тэгов</a>
                  </div>';
        }
    }

    if (!empty($this->paginator)) {
        $HTMLstr .= '<div class="paginator">'. $this->paginator .'</div>';
    }

} else {
    if (null != $user->getId()) {//сюда если база пустая
        if (empty($this->searchItem)) {
            $HTMLstr .= '
                <div class="fetchallOne" id="tag">
                <div class="head">
                База новостей ещё совсем пуста!
                </div>
                </div>
                </div>';
        } else {
            $HTMLstr .= '<div class="fetchallOne" id="tag">
                <div class="fetchallOneInsideText">
                Не найдено ни одного поста
                </div>
                <div class="fetchallOneInsideAct">
                <a href="index.php">Ко всем новостям</a>
                </div>
                </div>';
        }
    }
}
$HTMLstr .= '</div>';